//
//  MGNetworkHelper.m
//  CPManage
//
//  Created by lvho on 2017/4/18.
//  Copyright © 2017年 com.jiaoshou.chen. All rights reserved.
//

#import "MSNetworkHelper.h"
#import <SBJson4Writer.h>
@implementation MSNetworkHelper


+ (NSString *)toJsonString:(id)obj
{
    if ([obj isKindOfClass:[NSDictionary class]]) {
        NSDictionary *d = obj;
        if (d.count == 0) {
            return nil;
        }
    } else if ([obj isKindOfClass:[NSArray class]]) {
        NSArray *a = obj;
        if (a.count == 0) {
            return nil;
        }
    }
    SBJson4Writer *sbw = [[SBJson4Writer alloc]init];
    sbw.sortKeys = YES;
    
    return [sbw stringWithObject:obj];
}
/**
 *  判断对象是否为空
 *
 *  @param object 传入的实例
 *
 *  @return 返回值,NO表示该对象不为空,YES表示为空
 */
+ (BOOL)isNull:(id)object
{
    // 判断是否为空串
    if ([object isEqual:[NSNull null]]) {
        return YES;
    }
    else if ([object isKindOfClass:[NSNull class]])
    {
        return YES;
    }
    else if (object==nil){
        return YES;
    }else if ([object isKindOfClass:[NSString class]]){
        if ([object isEqualToString:@"(null)"] ||
            [object isEqualToString:@"<null>"] ||
            [object isEqualToString:@"<nil>"] ||
            [object isEqualToString:@""]) {
            return YES;
        }
    }
    return NO;
}

@end
